Skip to content

Lowercaseify Nexus request headers#1006

Merged
Sushisource merged 4 commits intomasterfrom
nexus-header-fixup
Sep 10, 2025
Merged

Lowercaseify Nexus request headers#1006
Sushisource merged 4 commits intomasterfrom
nexus-header-fixup

Conversation

@Sushisource
Copy link
Copy Markdown
Member

What was changed

Lowercaseify Nexus start request headers

Why?

So lang doesn't see weird duplicated camel and kebab case of the same header.

Checklist

  1. Closes [Feature Request] Nexus should deduplicate and lowercase inbound headers #993

  2. How was this tested:
    Existing integ test with modification

  3. Any docs updates needed?

@Sushisource Sushisource requested a review from a team as a code owner September 9, 2025 22:54
Comment thread sdk-core-protos/src/utilities.rs Outdated
Comment thread core/src/worker/nexus.rs
};

if let Some(ref mut req) = t.resp.request {
req.header = normalize_http_headers(std::mem::take(&mut req.header));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we std::mem::take here? Just for safety, to make sure that memory is cleared out?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just accept a mutable hash map reference in the normalize helper?

Copy link
Copy Markdown
Member Author

@Sushisource Sushisource Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows me to own the old map, therefore I can call into_iter and avoid copying all the values

Co-authored-by: Andrew Yuan <andrew.yuan@temporal.io>
@Sushisource Sushisource enabled auto-merge (squash) September 10, 2025 16:29
@Sushisource Sushisource merged commit 2cea5c3 into master Sep 10, 2025
29 of 31 checks passed
@Sushisource Sushisource deleted the nexus-header-fixup branch September 10, 2025 17:43
Copy link
Copy Markdown
Contributor

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry, forgot to publish this review, too late now)

Comment thread core/src/worker/nexus.rs
};

if let Some(ref mut req) = t.resp.request {
req.header = normalize_http_headers(std::mem::take(&mut req.header));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just accept a mutable hash map reference in the normalize helper?

/// Given a header map, lowercase all the keys and return it as a new map.
/// Any keys that are duplicated after lowercasing will clobber each other in underfined ordering.
pub fn normalize_http_headers(headers: HashMap<String, String>) -> HashMap<String, String> {
let mut new_headers = HashMap::new();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to accept a mutable map if we can, but if we must do it this way, would recommend either using an iter approach (HashMap's FromIterator just drops dupes) or at least using with_capacity instead of new.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot mutate hashmap keys. with_capacity, sure, but, it's lightyears away from being a bit of perf that matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Nexus should deduplicate and lowercase inbound headers

3 participants